package controlLayer;
import modelLayer.*;
import java.util.ArrayList;
import java.util.Scanner;

public class StatisticsCtr {
    
    private Employee emp;
    private EmployeeCtr empCtr;
    private ProductContainer prodCont;
    private OrderContainer ordCont;
    private RentContainer rentCont;
    
    public StatisticsCtr() {
        empCtr = new EmployeeCtr();
        prodCont = ProductContainer.getInstance();
        ordCont = OrderContainer.getInstance();
        rentCont = RentContainer.getInstance();
    }
    
    public double totalStock() {
        double stock = prodCont.totalStock();
        return stock;
    }
    
    public String generalStatistics() {
        String message = "Types of products on stock : " + prodCont.numberOfProducts();
        return message;
    }
    
    public Employee findEmployee(int ecpr) {
        emp = empCtr.findEmployee(ecpr);
        return emp;
    }

    public double ordersByEmployee(int cpr) {
        ArrayList<Order> empOrds = new ArrayList<>();
        double sales = 0;
        empOrds = ordCont.ordersByEmployee(cpr);
        String date = inputMonth();
        for(Order ord : empOrds) {
            if (ord.getDate().substring(3,5).equals(date)) {
                sales += ord.getTotalPrice();
            }
        }
        return sales;
    }
    
    public double ordersByMonth(String month) {
        ArrayList<Order> monthOrds = ordCont.ordersByMonth(month);
        double sales = 0;
        for (Order ord : monthOrds) {
            sales += ord.getTotalPrice();
        }
        return sales;
    }
    
    public double rentsByMonth(String month) {
        ArrayList<Rent> monthRents = rentCont.rentsByMonth(month);
        double sales = 0;
        for (Rent rent : monthRents) {
            sales += rent.getTotal();
        }
        return sales;
    }
    
    public String inputMonth() {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Enter the month for the statistics (mm) : ");
        String date = keyboard.nextLine();
        return date;
    }
}
